package com.itheima.springbootdemo.service.impl;

import com.itheima.springbootdemo.mapper.StudentMapper;
import com.itheima.springbootdemo.service.StudentService;
import com.itheima.springbootdemo.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public void add(Student student) {
        studentMapper.add(student);
    }

    @Override
    public void deleteById(Integer id) {
        if (id == null || id < 0) {
            return;
        }
        studentMapper.deleteById(id);
    }

    @Override
    public void update(Student student) {
        if (student == null) {
            return;
        }
        Integer id = student.getId();
        if (id == null || id < 0) {
            return;
        }
        studentMapper.update(student);
    }

    @Override
    public Student findById(Integer id) {
        if (id == null || id < 0) {
            return null;
        }
        return studentMapper.findById(id);
    }

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }
}
